import express from "express";
import multer from "multer";
import {
  uploadChunk,
  mergeChunks,
  getUploadedChunks,
  fastUpload, // 新增
  uploadImage,
} from "../controllers/uploadController.js";

const router = express.Router();
const storage = multer.memoryStorage(); //配置 multer 使用内存存储 (memoryStorage())，这意味着,上传的文件不会保存到磁盘,文件内容存储在内存的 Buffer 对象中
const upload = multer({ storage });

// 断点续传：获取已上传分片
router.get("/uploaded-chunks", getUploadedChunks);

// 上传分片
router.post("/upload-chunk", upload.single("file"), uploadChunk); //处理单个文件上传

// 合并分片
router.post("/merge-chunks", mergeChunks);

// 新增hash秒传检测
router.post("/fast-upload", fastUpload);

// 图片上传（el-upload 专用）
router.post("/upload-image", upload.single("file"), uploadImage);

export default router;
